package com.animationsp.acs.action;

//import java.text.SimpleDateFormat;
//import java.util.Date;
//
//import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.hongliang.util.FieldUtil;

import com.animationsp.acs.util.CookieManager;
import com.animationsp.acs.util.MyActionSupport;
import com.animationsp.acs.util.UserRoleUtil;
import com.opensymphony.webwork.ServletActionContext;
//import com.opensymphony.xwork.ActionContext;

public class Login extends MyActionSupport {
	

	private String password;

	private String username;
	

	public String execute() {
		
		if (FieldUtil.isEmpty(username) || FieldUtil.isEmpty(password)) {
			return LOGIN;
		}

		if ("reload".equals(username)) {
			setErr("不允许使用系统保留用户名");
			UserRoleUtil.reload();
			return LOGIN;
		}
		if (UserRoleUtil.passwordValid(username, password)) {
//			ActionContext.getContext().getSession().put("uu", username);
//			ActionContext.getContext().getSession().put(Constant.SESSION_USER,
//					username);
			
			HttpServletRequest req = ServletActionContext.getRequest();
			HttpServletResponse res = ServletActionContext.getResponse();
			CookieManager.setCookie(req,res,username);
//	System.out.println("---------<< "+ActionContext.getContext().getSession().get("Constant.SESSION_USER"));
			return SUCCESS;
		}

		setErr("用户名或密码错误");
		return LOGIN;
		
	}

	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}
}
